package com.itheima.model.vo;

import com.itheima.model.domain.Announcement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AnnouncementVo implements Serializable {
    private String id;
    private String title;
    private String description;
    private String created;
    private String updated;

    public static AnnouncementVo init(Announcement announcement) {
        AnnouncementVo vo = new AnnouncementVo();
        BeanUtils.copyProperties(announcement, vo);
        Date date1 = announcement.getCreated();
        Date date2 = announcement.getUpdated();
        vo.setCreated(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date1));
        vo.setUpdated(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date2));
        vo.setId(announcement.getId().toString());
        return vo;
    }
}
